home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
c01lab4.zip
/
LRMRDR
/
LRM_CHAP.ZIP
/
CHAP08.DOC
< prev
next >
Wrap
Text File
|
1992-04-21
|
39KB
|
855 lines
> 8. Visibility Rules
The rules defining the scope of declarations and the rules defining which
identifiers are visible at various points in the text of the program are
described in this chapter. The formulation of these rules uses the notion
of a declarative region.
References: declaration 3.1, declarative region 8.1, identifier 2.3, scope
8.2, visibility 8.3
> 8.1 Declarative Region
A declarative region is a portion of the program text. A single
declarative region is formed by the text of each of the following:
- A subprogram declaration, a package declaration, a task declaration,
or a generic declaration, together with the corresponding body, if
any. If the body is a body stub, the declarative region also includes
the corresponding subunit. If the program unit has subunits, they are
also included.
- An entry declaration together with the corresponding accept
statements.
- A record type declaration, together with a corresponding private or
incomplete type declaration if any, and together with a corresponding
record representation clause if any.
- A renaming declaration that includes a formal part, or a generic
parameter declaration that includes either a formal part or a
discriminant part.
- A block statement or a loop statement.
In each of the above cases, the declarative region is said to be associated
with the corresponding declaration or statement. A declaration is said to
occur immediately within a declarative region if this region is the
innermost region that encloses the declaration, not counting the
declarative region (if any) associated with the declaration itself.
A declaration that occurs immediately within a declarative region is said
to be local to the region. Declarations in outer (enclosing) regions are
said to be global to an inner (enclosed) declarative region. A local
entity is one declared by a local declaration; a global entity is one
declared by a global declaration.
Some of the above forms of declarative region include several disjoint
parts (for example, other declarative items can be between the declaration
of a package and its body). Each declarative region is nevertheless
considered as a (logically) continuous portion of the program text. Hence
if any rule defines a portion of text as the text that extends from some
specific point of a declarative region to the end of this region, then this
portion is the corresponding subset of the declarative region (for example
it does not include intermediate declarative items between the two parts of
a package).
Notes:
As defined in section 3.1, the term declaration includes basic
declarations, implicit declarations, and those declarations that are part
of basic declarations, for example, discriminant and parameter
specifications. It follows from the definition of a declarative region
that a discriminant specification occurs immediately within the region
associated with the enclosing record type declaration. Similarly, a
parameter specification occurs immediately within the region associated
with the enclosing subprogram body or accept statement.
The package STANDARD forms a declarative region which encloses all library
units: the implicit declaration of each library unit is assumed to occur
immediately within this package (see sections 8.6 and 10.1.1).
Declarative regions can be nested within other declarative regions. For
example, subprograms, packages, task units, generic units, and block
statements can be nested within each other, and can contain record type
declarations, loop statements, and accept statements.
References: accept statement 9.5, basic declaration 3.1, block statement
5.6, body stub 10.2, declaration 3.1, discriminant part 3.7.1, discriminant
specification 3.7.1, entry declaration 9.5, formal part 6.1, generic body
12.2, generic declaration 12.1, generic parameter declaration 12.1,
implicit declaration 3.1, incomplete type declaration 3.8.1, library unit
10.1, loop statement 5.5, package 7, package body 7.1, package declaration
7.1, parameter specification 6.1, private type declaration 7.4, record
representation clause 13.4, record type 3.7, renaming declaration 8.5,
standard package 8.6, subprogram body 6.3, subprogram declaration 6.1,
subunit 10.2, task body 9.1, task declaration 9.1, task unit 9
> 8.2 Scope of Declarations
For each form of declaration, the language rules define a certain portion
of the program text called the scope of the declaration. The scope of a
declaration is also called the scope of any entity declared by the
declaration. Furthermore, if the declaration associates some notation with
a declared entity, this portion of the text is also called the scope of
this notation (either an identifier, a character literal, an operator
symbol, or the notation for a basic operation). Within the scope of an
entity, and only there, there are places where it is legal to use the
associated notation in order to refer to the declared entity. These places
are defined by the rules of visibility and overloading.
The scope of a declaration that occurs immediately within a declarative
region extends from the beginning of the declaration to the end of the
declarative region; this part of the scope of a declaration is called the
immediate scope. Furthermore, for any of the declarations listed below,
the scope of the declaration extends beyond the immediate scope:
(a) A declaration that occurs immediately within the visible part of a
package declaration.
(b) An entry declaration.
(c) A component declaration.
(d) A discriminant specification.
(e) A parameter specification.
(f) A generic parameter declaration.
In each of these cases, the given declaration occurs immediately within
some enclosing declaration, and the scope of the given declaration extends
to the end of the scope of the enclosing declaration.
In the absence of a subprogram declaration, the subprogram specification
given in the subprogram body or in the body stub acts as the declaration
and rule (e) applies also in such a case.
Note:
The above scope rules apply to all forms of declaration defined by section
3.1; in particular, they apply also to implicit declarations. Rule (a)
applies to a package declaration and thus not to the package specification
of a generic declaration. For nested declarations, the rules (a) through
(f) apply at each level. For example, if a task unit is declared in the
visible part of a package, the scope of an entry of the task unit extends
to the end of the scope of the task unit, that is, to the end of the scope
of the enclosing package. The scope of a use clause is defined in section
8.4.
References: basic operation 3.3.3, body stub 10.2, character literal 2.5,
component declaration 3.7, declaration 3.1, declarative region 8.1,
discriminant specification 3.7.1, entry declaration 9.5, extends 8.1,
generic declaration 12.1, generic parameter declaration 12.1, identifier
2.3, implicit declaration 3.1, occur immediately within 8.1, operator
symbol 6.1, overloading 6.6 8.7, package declaration 7.1, package
specification 7.1, parameter specification 6.1, record type 3.7, renaming
declaration 8.5, subprogram body 6.3, subprogram declaration 6.1, task
declaration 9.1, task unit 9, type declaration 3.3.1, use clause 8.4,
visibility 8.3, visible part 7.2
> 8.3 Visibility
The meaning of the occurrence of an identifier at a given place in the text
is defined by the visibility rules and also, in the case of overloaded
declarations, by the overloading rules. The identifiers considered in th